/**
 * @description 系统路由管理
 */
import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
// 定义路由
export const constantRoutes = [
  /**
   * @desc 首页
   * 1、登录成功之后就跳转到这个界面
   */
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */
            "@/views/dashboard/index"
          ),
        meta: {
          title: "首页",
          icon: "dashboard",
        },
      },
    ],
  },
  /**
   * @desc 理论教学模块
   */
  {
    path: "/theoretical-teaching",
    component: Layout,
    // redirect: "/theoretical-teaching",
    meta: {
      title: "理论教学模块",
      icon: "el-icon-postcard",
    },
    children: [
      {
        path: "theoretical-teaching",
        name: "theoretical-teaching",
        component: () =>
          import(
            /* webpackChunkName: "theoretical-teaching-sort" */
            "@/views/theoretical-teaching/theoretical-teaching-sort.vue"
          ),
        meta: {
          title: "教学资源分类管理",
          icon: "el-icon-reading",
        },
      },
      {
        path: "/theoretical-teaching-list",
        name: "theoretical-teaching-list",
        component: () =>
          import(
            /* webpackChunkName: "theoretical-teaching-list" */
            "@/views/theoretical-teaching/theoretical-teaching-list"
          ),
        meta: {
          title: "教学资源列表管理",
          icon: "el-icon-postcard",
        },
      },
    ],
  },
  /**
   * @desc 实践操作
   */
  {
    path: "/practical-operation",
    component: Layout,
    // redirect: "/practical-operation",

    children: [
      {
        path: "/practical-operation",
        name: "practical-operation",
        component: () =>
          import(
            /* webpackChunkName: "practical-operation" */
            "@/views/resource/practical-operation.vue"
          ),
        meta: {
          title: "实践操作",
          icon: "table",
        },
      },
    ],
  },
  /**
   * @desc 商业流程案例分析
   */
  {
    path: "/case",
    component: Layout,
    redirect: "/case",
    children: [
      {
        path: "case",
        name: "case",
        component: () =>
          import(
            /* webpackChunkName: "case" */
            "@/views/case-analysis/case"
          ),
        meta: {
          title: "商业流程案例分析",
          icon: "table",
        },
      },
    ],
  },

  /**
   * @desc 用户管理
   */
  {
    path: "/user",
    component: Layout,
    // redirect: "/user",
    name: "User",
    meta: {
      title: "用户管理",
      icon: "table",
    },
    children: [
      {
        path: "user/sort",
        name: "userSort",
        component: () =>
          import(
            /* webpackChunkName: "user-sort" */
            "@/views/user/user-sort.vue"
          ),
        meta: {
          title: "用户分类",
          icon: "tree",
        },
      },
      {
        path: "user/list",
        name: "userList",
        component: () =>
          import(
            /* webpackChunkName: "user-list" */
            "@/views/user/user-list.vue"
          ),
        meta: {
          title: "用户列表",
          icon: "table",
        },
      },
    ],
  },
  /**
   * @desc 帮助
   */
  {
    path: "/help",
    component: Layout,
    // redirect: "/help",
    children: [
      {
        path: "help",
        name: "Help",
        component: () =>
          import(
            /* webpackChunkName: "help" */
            "@/views/help/index"
          ),
        meta: {
          title: "帮助",
          icon: "help",
        },
      },
    ],
  },
  /**
   * @desc 登录
   */
  {
    path: "/login",
    component: () =>
      import(
        /* webpackChunkName: "login" */
        "@/views/login/index"
      ),
    hidden: true,
  },
  /**
   * @desc 注册
   */
  {
    path: "/register",
    component: () =>
      import(
        /* webpackChunkName: "register" */
        "@/views/register/index"
      ),
    hidden: true,
  },
  /**
   * @desc 404
   */
  {
    path: "/404",
    component: () =>
      import(
        /* webpackChunkName: "404" */
        "@/views/404"
      ),
    hidden: true,
  },
];
// 创建路由
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  // reset router
  router.matcher = newRouter.matcher;
}

export default router;
